package main

import (
	"flag"
	"fmt"
	"gitee.com/min65535/gotechback/techback/conf"
	"gitee.com/min65535/gotechback/techback/util/diagnostics"
	"gitee.com/min65535/gotechback/techback/util/logger"
	"github.com/go-kratos/kratos/v2"
	"github.com/go-kratos/kratos/v2/transport/http"
)

var (
	configFile = flag.String("config", "../../configs/config.yaml", "default configuration file")
)

// func newApp(hs *http.Server, gs *grpc.Server) *kratos.App {
func newApp(hs *http.Server) *kratos.App {
	return kratos.New(
		kratos.Name("gotech"),
		kratos.Version("tech-v1.0.0"),
		kratos.Metadata(map[string]string{}),
		kratos.Server(
			hs,
			// gs,
		),
	)
}

func main() {
	flag.Parse()
	logger.Init(logger.WithLogPath(fmt.Sprintf("/data/gotech/logs/%s.log", "gotechback")))
	cfg, err := conf.InitConfig(*configFile)
	if err != nil {
		panic(err)
	}
	diagnostics.StartDiagnosticTool(cfg.Diagnostics)

	app, cleanup, err := initApp(cfg)
	if err != nil {
		panic(err)
	}
	defer cleanup()

	// start and wait for stop signal
	if err = app.Run(); err != nil {
		panic(err)
	}
}
